//JS
Page({
  data: {
    textData: [],
    totalPrice: 0,// 总价
  },
  // 初始化加载
  onLoad() {
    this.getValue();
    this.totalPrice();
  },
  onShow(){
    this.getValue();
    this.totalPrice();
  },
  getValue() {
    let back = wx.getStorageSync('selectedData') || [];
    if (Array.isArray(back)) {
      this.setData({
        textData: back
      });
    } else {
      this.setData({
        textData: [] 
      });
    }
    this.totalPrice();
  },
  totalPrice(){
    let price = 0;
    this.data.textData.forEach((item)=>{
      if(item){
        price+=item.price * item.num;
      }
    })
    this.setData({
      totalPrice: price, // 更新页面显示的总价
    });
  },
  toOrders() {
    let dindanItems = this.data.textData;
    wx.setStorageSync('dindanData', dindanItems); // 存储选中的商品到本地存储
  }
})